package cn.south.campus.common.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.annotation.PostConstruct;

/**
 * @author chow
 * @since 2023/3/21
 */
@Configuration
@Data
@PropertySource(value = "classpath:file.properties")
public class FileUploadConfig {

    @Value("${file.type}")
    private String uploadType;
    /**
     * 资源映射路径 前缀
     */
    @Value("${file.local.prefix}")
    public String localFilePrefix;
    /**
     * 域名或本机访问地址
     */
    @Value("${file.local.domain}")
    public String domain;
    /**
     * 上传文件存储在本地的根路径
     */
    @Value("${file.local.path}")
    private String localFilePath;

    @Value("${file.allowType}")
    private String allowFileType;

    @Value("${file.maxSize}")
    private long maxSize;

    public static String UPLOAD_TYPE;
    public static String LOCAL_FILE_PREFIX;
    public static String DOMAIN;
    public static String LOCAL_FILE_PATH;
    public static String ALLOW_FILE_TYPE;
    public static long MAX_SIZE;

    @PostConstruct
    public void init() {
        UPLOAD_TYPE = uploadType;
        LOCAL_FILE_PREFIX = localFilePrefix;
        DOMAIN = domain;
        LOCAL_FILE_PATH = localFilePath;
        ALLOW_FILE_TYPE = allowFileType;
        MAX_SIZE = maxSize;
    }
}
